#ifndef SIGUSR1_HANDLER_H_
#define SIGUSR1_HANDLER_H_

#include <signal.h>
#include <assert.h>

#include "EventHandler.h"

class SIGUSR1_Handler : public EventHandler {
	private:
		sig_atomic_t gracefulQuit;

	public:
		SIGUSR1_Handler() {
			this->gracefulQuit = 0;
		}

		~SIGUSR1_Handler() {
		}

		virtual int handleSignal(int signum) {
			assert(signum == SIGUSR1);
			this->gracefulQuit = 1;
			return 0;
		}

		sig_atomic_t getGracefulQuit() {
			return this->gracefulQuit;
		}
		
		void restaurarEstado() {
			this->gracefulQuit = 0;
		}

		void bloquear() {
			sigset_t sa;
			sigemptyset(&sa);
			sigaddset(&sa, SIGUSR1);
			sigprocmask(SIG_BLOCK, &sa, NULL);
		}

};

#endif /* SIGUSR1_HANDLER_H_ */
